package com.timingdemo.job;

import org.quartz.*;

import java.util.Date;

public class HelloJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        // 获取调度器实例
        Scheduler scheduler = context.getScheduler();

        // 获取触发器实例
        Trigger trigger = context.getTrigger();

        // 获取任务的详细信息
        JobDetail jobDetail = context.getJobDetail();

        // 获取任务的名字和分组
        String jobName = jobDetail.getKey().getName();
        String jobGroup = jobDetail.getKey().getGroup();

        // 获取触发器的名字和分组
        String triggerName = trigger.getKey().getName();
        String triggerGroup = trigger.getKey().getGroup();

        // 获取任务的执行时间
        Date fireTime = context.getFireTime();

        // 获取下一次触发时间
        Date nextFireTime = context.getNextFireTime();

        // 获取任务的合并数据
        JobDataMap jobDataMap = context.getMergedJobDataMap();

        // 记录日志
        System.out.println("Executing Sample Job with details:");
        System.out.println("Job Name: " + jobName);
        System.out.println("Job Group: " + jobGroup);
        System.out.println("Trigger Name: " + triggerName);
        System.out.println("Trigger Group: " + triggerGroup);
        System.out.println("Fire Time: " + fireTime);
        System.out.println("Next Fire Time: " + nextFireTime);
        System.out.println("Job Data Map: " + jobDataMap);

        System.out.println("Hello, Quartz! " + new Date());
    }
}
